import 'dart:io';
import 'package:jverify/jverify.dart';
import 'package:nyh_motorcade_app/styles/colors.dart';

class JVerifyUtils {
  static late Jverify _jverify;

  static init() {
    _jverify = Jverify();
    _jverify.setDebugMode(true);
    _jverify.setup(appKey: "b0c36a5f373b3fe042e029f7", channel: "developer-default");
  }

  static getJVerify() {
    return _jverify;
  }

  static setCustomAuthorizationView() {
    /// 自定义授权的 UI 界面，以下设置的图片必须添加到资源文件里，
    /// android项目将图片存放至drawable文件夹下，可使用图片选择器的文件名,例如：btn_login.xml,入参为"btn_login"。
    /// ios项目存放在 Assets.xcassets。
    JVUIConfig uiConfig = JVUIConfig();
    if (Platform.isIOS) {
      uiConfig.authBackgroundImage = "bg";
      //导航栏返回按钮图标
      uiConfig.navReturnImgPath = "ic_back";
      //导航栏背景颜色
      uiConfig.navColor = Colours.color_white.value;

      //logo宽
      uiConfig.logoWidth = 80;
      //logo高
      uiConfig.logoHeight = 80;
      //logoY轴偏移
      uiConfig.logoOffsetY = 40;
      uiConfig.logoVerticalLayoutItem = JVIOSLayoutItem.ItemSuper;
      uiConfig.logoHidden = false;
      //logo图标
      uiConfig.logoImgPath = "ic_logo";

      //手机号宽
      uiConfig.numberFieldWidth = 200;
      //手机号高
      uiConfig.numberFieldHeight = 40;
      //手机号Y轴偏移
      uiConfig.numFieldOffsetY = 20;
      uiConfig.numberVerticalLayoutItem = JVIOSLayoutItem.ItemLogo;
      //手机号颜色
      uiConfig.numberColor = Colours.color_text_theme.value;
      //手机号字体
      uiConfig.numberSize = 24;

      //认证服务Y轴偏移
      uiConfig.sloganOffsetY = 20;
      uiConfig.sloganVerticalLayoutItem = JVIOSLayoutItem.ItemNumber;
      //认证服务颜色
      uiConfig.sloganTextColor = Colours.color_9fa0ab.value;
      //认证服务字体
      uiConfig.sloganTextSize = 12;

      //登录按钮宽
      uiConfig.logBtnWidth = 295;
      //登录按钮高
      uiConfig.logBtnHeight = 42;
      //登录按钮Y轴偏移
      uiConfig.logBtnOffsetY = 40;
      uiConfig.logBtnVerticalLayoutItem = JVIOSLayoutItem.ItemSlogan;
      //登录按钮文字
      uiConfig.logBtnText = "本机号码一键登录";
      //登录按钮颜色
      uiConfig.logBtnTextColor = Colours.color_white.value;
      //登录按钮字体
      uiConfig.logBtnTextSize = 16;
      //登录按钮背景图片
      uiConfig.loginBtnNormalImage = "login_btn_bg"; //图片必须存在
      uiConfig.loginBtnPressedImage = "login_btn_bg"; //图片必须存在
      uiConfig.loginBtnUnableImage = "login_btn_bg"; //图片必须存在

      //隐私条款颜色
      uiConfig.clauseBaseColor = Colours.color_9fa0ab.value;
      uiConfig.clauseColor = Colours.color_theme.value;
      //隐私条款字体
      uiConfig.privacyTextSize = 11;
      //隐私条款不选中时点击登录按钮默认弹出toast
      uiConfig.privacyHintToast = true;
      //隐私条款默认选中状态
      uiConfig.privacyState = true;
      //隐私条款checkbox是否相对协议文字纵向居中
      uiConfig.privacyCheckboxInCenter = true;
      //隐私条款相对于屏幕左边 x 轴偏移
      uiConfig.privacyOffsetX = 40;
      //隐私条款相对于授权页面底部下边缘 y 偏移
      uiConfig.privacyOffsetY = 30;
      //隐私协议选中图标大小
      uiConfig.privacyCheckboxSize = 12;
      //隐私条款选中图标
      uiConfig.checkedImgPath = "ic_check";
      //隐私条款未选中图标
      uiConfig.uncheckedImgPath = "ic_uncheck";
      uiConfig.privacyVerticalLayoutItem = JVIOSLayoutItem.ItemSuper;

      //隐私协议web返回按钮图标
      uiConfig.privacyNavReturnBtnImage = "ic_back_white";
      //隐私协议web导航栏颜色
      uiConfig.privacyNavColor = Colours.color_theme.value;
      //隐私协议web标题颜色
      uiConfig.privacyNavTitleTextColor = Colours.white.value;
      //隐私协议web标题字体
      uiConfig.privacyNavTitleTextSize = 20;

      //ios授权页状态栏样式
      uiConfig.authStatusBarStyle = JVIOSBarStyle.StatusBarStyleDarkContent;
      //ios隐私协议web状态栏样式
      uiConfig.privacyStatusBarStyle = JVIOSBarStyle.StatusBarStyleDefault;

      //ios弹出方式
      uiConfig.modelTransitionStyle = JVIOSUIModalTransitionStyle.CrossDissolve;
    } else {
      //授权页状态栏是否跟导航栏同色
      uiConfig.statusBarColorWithNav = true;
      //授权页状态栏是否为暗色
      uiConfig.statusBarDarkMode = true;

      //导航栏返回按钮图标
      uiConfig.navReturnImgPath = "ic_back";
      //导航栏背景颜色
      uiConfig.navColor = Colours.color_white.value;

      //手机号颜色
      uiConfig.numberColor = Colours.color_text_theme.value;
      //手机号字体
      uiConfig.numberSize = 24;

      //认证服务颜色
      uiConfig.sloganTextColor = Colours.color_9fa0ab.value;
      //认证服务字体
      uiConfig.sloganTextSize = 12;

      //登录按钮背景图片
      uiConfig.logBtnBackgroundPath = "login_btn_bg";
      //登录按钮高度
      uiConfig.logBtnHeight = 48;
      //登录按钮文字
      uiConfig.logBtnText = "本机号码一键登录";
      //登录按钮颜色
      uiConfig.logBtnTextColor = Colours.color_white.value;
      //登录按钮字体
      uiConfig.logBtnTextSize = 16;

      //隐私条款颜色
      uiConfig.clauseBaseColor = Colours.color_9fa0ab.value;
      uiConfig.clauseColor = Colours.color_theme.value;
      //隐私条款字体
      uiConfig.privacyTextSize = 12;
      //隐私条款不选中时点击登录按钮默认弹出toast
      uiConfig.privacyHintToast = true;
      //隐私条款默认选中状态
      uiConfig.privacyState = true;
      //隐私条款checkbox是否相对协议文字纵向居中
      uiConfig.privacyCheckboxInCenter = false;
      //隐私条款相对于屏幕左边 x 轴偏移
      uiConfig.privacyOffsetX = 60;
      //隐私条款相对于授权页面底部下边缘 y 偏移
      uiConfig.privacyOffsetY = 30;
      //隐私协议选中图标大小
      uiConfig.privacyCheckboxSize = 15;
      //隐私条款选中图标
      uiConfig.checkedImgPath = "ic_check";
      //隐私条款未选中图标
      uiConfig.uncheckedImgPath = "ic_uncheck";

      //隐私协议web返回按钮图标
      uiConfig.privacyNavReturnBtnImage = "ic_back";
      //隐私协议web导航栏颜色
      uiConfig.privacyNavColor = Colours.color_theme.value;
      //隐私协议web标题颜色
      uiConfig.privacyNavTitleTextColor = Colours.white.value;
      //隐私协议web标题字体
      uiConfig.privacyNavTitleTextSize = 20;
      //隐私协议web状态栏是否与导航栏同色
      uiConfig.privacyStatusBarColorWithNav = true;
      //隐私协议web状态栏是否暗色
      uiConfig.privacyStatusBarDarkMode = true;
    }

    //拉起授权页时是否需要显示默认动画
    uiConfig.needStartAnim = true;
    //关闭授权页时是否需要显示默认动画
    uiConfig.needCloseAnim = true;

    _jverify.setCustomAuthorizationView(false, uiConfig);
  }
}
